1 package org.smartcomps.twister.engine.core.dynamic; 2 3 import junit.framework.TestCase; 4 5 import org.smartcomps.twister.engine.priv.core.dynamic.ExecutionContextFactory; 6 import org.smartcomps.twister.engine.priv.core.dynamic.ProcessInstanceFactory; 7 import org.smartcomps.twister.engine.priv.core.dynamic.ProcessInstance; 8 import org.smartcomps.twister.engine.priv.core.dynamic.InvokeEC; 9 import org.smartcomps.twister.engine.priv.core.dynamic.impl.xao.VariableXAO; 10 import org.smartcomps.twister.engine.priv.core.definition.*; 11 import org.smartcomps.twister.engine.priv.messaging.impl.DefaultMessageBrokerImpl; 12 import org.smartcomps.twister.engine.core.definition.TestInvoke; 13 import org.smartcomps.twister.engine.core.definition.TestProcess; 14 import org.smartcomps.twister.engine.exception.SelectionFailureException; 15 import org.smartcomps.twister.common.transaction.TransactionManager; 16 import org.smartcomps.twister.common.lifecycle.LifecycleManager; 17 18 import org.dom4j.Document; 19 20 import net.sf.hibernate.tool.hbm2ddl.SchemaExport; 21 import net.sf.hibernate.cfg.Configuration; 22 23 import java.util.Map; 24 import java.util.HashMap; 25 26 public class TestInvokeEC extends TestCase { 27 28 public InvokeEC testInvokeEC = null; 29 30 private TestInvoke testInvoke = new TestInvoke(); 31 private TestProcess testProcess = new TestProcess(); 32 33 protected void setUp() throws Exception { 34 LifecycleManager.getLifecycleManager().createResources(); 35 LifecycleManager.getLifecycleManager().startResources(); 36 37 SchemaExport schemaExport = new SchemaExport(new Configuration().configure()); 38 schemaExport.create(true, true); 39 40 TransactionManager.beginTransaction(); 41 testProcess.testCreateWithCorrelation(); 42 } 43 44 protected void tearDown() throws Exception { 45 TransactionManager.commitTransaction(); 46 47 LifecycleManager.getLifecycleManager().stopResources(); 48 LifecycleManager.getLifecycleManager().destroyResources(); 49 } 50 51 public void testCreate() throws Exception { 52 // Invoke is using the process created in TestProcess 53 testInvoke.testCreate(); 54 55 Map corrProp = new HashMap(); 56 corrProp.put(TestProcess.CORRELATION_PROP1, "2578"); 57 corrProp.put(TestProcess.CORRELATION_PROP2, "12"); 58 ProcessInstance pi = ProcessInstanceFactory.createProcessInstance(TestInvoke.invoke.getProcess(), 59 TestProcess.CORRELATION_NAME, corrProp); 60 InvokeEC invokeEC = (InvokeEC) ExecutionContextFactory.createExecutionContext(TestInvoke.invoke, pi); 61 62 TransactionManager.commitTransaction(); 63 TransactionManager.beginTransaction(); 64 65 ProcessInstance createdInstance = ProcessInstanceFactory.findInstanceByCorrelation(TestProcess.CORRELATION_NAME, corrProp); 66 assertTrue("Instance child ec is not a InvokeEC", 67 createdInstance.getChildExecutionContext() instanceof InvokeEC); 68 testInvokeEC = (InvokeEC) createdInstance.getChildExecutionContext(); 69 } 70 71 public void testExecuteWithSelectionFailure() throws Exception { 72 // Invoke is using the process created in TestProcess 73 testInvoke.testCreate(); 74 75 Map corrProp = new HashMap(); 76 corrProp.put(TestProcess.CORRELATION_PROP1, "2578"); 77 corrProp.put(TestProcess.CORRELATION_PROP2, "12"); 78 79 try { 80 TestInvoke.invoke.execute(TestProcess.CORRELATION_NAME, corrProp); 81 fail("Executing an invoke with an input variable that has not been set should " + 82 "result with a selection failure exception."); 83 } catch (SelectionFailureException sfe) { 84 // We should get a selection failure error as the input variable of invoke has 85 // not been set 86 } 87 } 88 89 public void testExecuteWithInput() throws Exception { 90 Assign firstActivity = createInvoke("inputVar", null); 91 92 Map corrProp = new HashMap(); 93 corrProp.put(TestProcess.CORRELATION_PROP1, "2578"); 94 corrProp.put(TestProcess.CORRELATION_PROP2, "12"); 95 96 firstActivity.execute(TestProcess.CORRELATION_NAME, corrProp); 97 98 TransactionManager.commitTransaction(); 99 TransactionManager.beginTransaction(); 100 101 ProcessInstance createdInstance = ProcessInstanceFactory.findInstanceByCorrelation(TestProcess.CORRELATION_NAME, corrProp); 102 assertEquals("Process is not completed after execution ended", ProcessInstance.COMPLETED, createdInstance.getStatus()); 103 assertNotNull("The message produced by the invoke has not been received by the MessageBroker", 104 DefaultMessageBrokerImpl.getMessage("partner", "porttype", "operation")); 105 } 106 107 public void testExecuteWithInputOutput() throws Exception { 108 Assign firstActivity = createInvoke("inputVar", null); 109 110 Map corrProp = new HashMap(); 111 corrProp.put(TestProcess.CORRELATION_PROP1, "2578"); 112 corrProp.put(TestProcess.CORRELATION_PROP2, "12"); 113 114 firstActivity.execute(TestProcess.CORRELATION_NAME, corrProp); 115 116 TransactionManager.commitTransaction(); 117 TransactionManager.beginTransaction(); 118 119 ProcessInstance createdInstance = ProcessInstanceFactory.findInstanceByCorrelation(TestProcess.CORRELATION_NAME, corrProp); 120 assertEquals("Process is not completed after execution ended", ProcessInstance.COMPLETED, createdInstance.getStatus()); 121 assertNotNull("The message produced by the invoke has not been received by the MessageBroker", 122 DefaultMessageBrokerImpl.getMessage("partner", "porttype", "operation")); 123 Document outputVariable = VariableXAO.getVariable(TestProcess.testProcess.getName(), "inputVar", createdInstance.getId()); 124 System.out.println("Output Variable : " + outputVariable); 125 assertNotNull("The invoke didn't store any variable as output", outputVariable); 126 } 127 128 private Assign createInvoke(String input, String output) throws Exception { 129 Sequence sequence = (Sequence) ActivityFactory.createActivity(Sequence.class, TestProcess.testProcess); 130 Assign assign = (Assign) ActivityFactory.createActivity(Assign.class, sequence); 131 Assignment assignement = ActivityFactory.addAssignment(assign, Assignment.EXPRESSION, Assignment.VARIABLE_PART); 132 assignement.setFromFirstValue("0"); 133 assignement.setToFirstValue("inputVar"); 134 assignement.setToSecondValue("main"); 135 136 Invoke invoke = (Invoke) ActivityFactory.createActivity(Invoke.class, sequence); 137 invoke.setOperation("operation"); 138 invoke.setPartner("partner"); 139 invoke.setPortType("porttype"); 140 invoke.setInputVariable(input); 141 invoke.setOutputVariable(output); 142 143 return assign; 144 } 145 146 147 }

This page was automatically generated by Maven